


package com.hm.jiaowuxitong.ui;

        import com.hm.jiaowuxitong.util.DBUtil;
        import com.hm.jiaowuxitong.util.UIUtil;

        import javax.swing.*;
        import java.awt.*;
        import java.awt.event.MouseEvent;
        import java.awt.event.MouseListener;

public class UpdataClassInfoUI {
    private int frame_width=770;
    private int frame_height=460;


    public UpdataClassInfoUI(){
        //创建添加学生信息的面板
        JFrame frame=new JFrame("修改班级信息");
        //设置面板的宽高
        frame.setSize(frame_width,frame_height);
        //禁止面板放大缩小
        frame.setResizable(true);
        //创建画布
        JPanel panel=new JPanel();
        //创建方向布局
        SpringLayout layout=new SpringLayout();
        panel.setLayout(layout);
        //创建文本框控件
        JLabel label1=new JLabel("修改的班级号:");
        layout.putConstraint(SpringLayout.WEST,label1,270,SpringLayout.WEST,panel);
        layout.putConstraint(SpringLayout.NORTH,label1,50,SpringLayout.NORTH,panel);
        label1.setForeground(Color.black);
        label1.setFont(new Font(" ", 3, 20));
        //创建文本编辑框控件
        JTextField jtf1=new JTextField(15);
        layout.putConstraint(SpringLayout.NORTH,jtf1,57,SpringLayout.NORTH,panel);
        layout.putConstraint(SpringLayout.WEST,jtf1,5,SpringLayout.EAST,label1);
        jtf1.setForeground(Color.black);
        jtf1.setFont(new Font(" ", 3, 15));
        //创建文本框控件
        JLabel label2=new JLabel("修改班级名称为:");
        layout.putConstraint(SpringLayout.WEST,label2,185,SpringLayout.WEST,panel);
        layout.putConstraint(SpringLayout.NORTH,label2,10,SpringLayout.SOUTH,label1);
        label2.setForeground(Color.black);
        label2.setFont(new Font(" ", 3, 20));
        //创建文本编辑框控件
        JTextField jtf2=new JTextField(15);
        layout.putConstraint(SpringLayout.WEST,jtf2,5,SpringLayout.EAST,label2);
        layout.putConstraint(SpringLayout.NORTH,jtf2,10,SpringLayout.SOUTH,jtf1);
        jtf2.setForeground(Color.black);
        jtf2.setFont(new Font(" ", 3, 15));
        //创建文本框控件
        JLabel label3=new JLabel("所属学院修改为:");
        layout.putConstraint(SpringLayout.WEST,label3,185,SpringLayout.WEST,panel);
        layout.putConstraint(SpringLayout.NORTH,label3,10,SpringLayout.SOUTH,label2);
        label3.setForeground(Color.black);
        label3.setFont(new Font(" ", 3, 20));
        //创建文本编辑框控件
        JTextField jtf3=new JTextField(15);
        layout.putConstraint(SpringLayout.WEST,jtf3,5,SpringLayout.EAST,label3);
        layout.putConstraint(SpringLayout.NORTH,jtf3,10,SpringLayout.SOUTH,jtf2);
        jtf3.setForeground(Color.black);
        jtf3.setFont(new Font(" ", 3, 15));
        //创建文本框控件
        JLabel label4=new JLabel("班级人数修改为:");
        layout.putConstraint(SpringLayout.WEST,label4,185,SpringLayout.WEST,panel);
        layout.putConstraint(SpringLayout.NORTH,label4,10,SpringLayout.SOUTH,label3);
        label4.setForeground(Color.black);
        label4.setFont(new Font(" ", 3, 20));
        //创建文本编辑框控件
        JTextField jtf4=new JTextField(15);
        layout.putConstraint(SpringLayout.WEST,jtf4,5,SpringLayout.EAST,label4);
        layout.putConstraint(SpringLayout.NORTH,jtf4,10,SpringLayout.SOUTH,jtf3);
        jtf4.setForeground(Color.black);
        jtf4.setFont(new Font(" ", 3, 15));
        //创建文本框控件
        JLabel label5=new JLabel("班主任修改为:");
        layout.putConstraint(SpringLayout.WEST,label5,205,SpringLayout.WEST,panel);
        layout.putConstraint(SpringLayout.NORTH,label5,10,SpringLayout.SOUTH,label4);
        label5.setForeground(Color.black);
        label5.setFont(new Font(" ", 3, 20));
        //创建文本编辑框控件
        JTextField jtf5=new JTextField(15);
        layout.putConstraint(SpringLayout.WEST,jtf5,5,SpringLayout.EAST,label5);
        layout.putConstraint(SpringLayout.NORTH,jtf5,10,SpringLayout.SOUTH,jtf4);
        jtf5.setForeground(Color.black);
        jtf5.setFont(new Font(" ", 3, 15));
        //创建提交按钮
        JButton button=new JButton("提交");
        layout.putConstraint(SpringLayout.WEST,button,305,SpringLayout.WEST,panel);
        layout.putConstraint(SpringLayout.NORTH,button,300,SpringLayout.NORTH,panel);
        button.setForeground(Color.black);
        button.setFont(new Font(" ", 3, 15));
        JButton button1=new JButton("返回");
        layout.putConstraint(SpringLayout.WEST,button1,20,SpringLayout.EAST,button);
        layout.putConstraint(SpringLayout.NORTH,button1,300,SpringLayout.NORTH,panel);
        button1.setForeground(Color.black);
        button1.setFont(new Font(" ", 3, 15));

        JLabel img=new JLabel();
        ImageIcon imageIcon = new ImageIcon("Image/Raa.jpg");  // 将"path/to/your/image.jpg"替换为你的图片路径
        img.setIcon(imageIcon);
        //把所有控件添加至画布
        panel.add(label1);
        panel.add(jtf1);
        panel.add(label2);
        panel.add(jtf2);
        panel.add(label3);
        panel.add(jtf3);
        panel.add(label4);
        panel.add(jtf4);
        panel.add(label5);
        panel.add(jtf5);
        panel.add(button);
        panel.add(button1);
        panel.add(img);
        //把画布添加至面板
        frame.setContentPane(panel);
        //将面板中央显示
        new UIUtil().center(frame,frame_width,frame_height);
        //将面板显示
        frame.setVisible(true);
        //添加提交按钮的点击事件
        button.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {

            }

            @Override
            public void mousePressed(MouseEvent e) {
                //获得所有编辑框中添加的内容信息
                String personId=jtf1.getText();
                String name=jtf2.getText();
                String age=jtf3.getText();
                String sex=jtf4.getText();
                String classes=jtf5.getText();
                if (!personId.isEmpty()&&name.isEmpty()&&age.isEmpty()&&sex.isEmpty()&&classes.isEmpty())  {
                    delete(personId);
                    // 处理文本框已输入的情况
                }

                if (!name.isEmpty()&&!personId.isEmpty())  {
                    UpdateClassName(name,personId);
                    System.out.println("修改班级名称成功");
                    // 处理文本框已输入的情况
                }
                if (!age.isEmpty()&&!personId.isEmpty())  {
                    UpdateClassAcadem(age,personId);
                    System.out.println("修改所属学院成功");
                    // 处理文本框已输入的情况
                }
                if (!sex.isEmpty()&&!personId.isEmpty())  {
                    UpdateClassNunber(name,classes);
                    System.out.println("修改班级人数成功");
                    // 处理文本框已输入的情况
                }
                if (!classes.isEmpty()&&!personId.isEmpty())  {
                    UpdateClassNunber(classes,personId);
                    System.out.println("修改班主任成功");
                    // 处理文本框已输入的情况
                }






            }

            @Override
            public void mouseReleased(MouseEvent e) {

            }

            @Override
            public void mouseEntered(MouseEvent e) {

            }

            @Override
            public void mouseExited(MouseEvent e) {

            }
        });
        button1.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {

            }

            @Override
            public void mousePressed(MouseEvent e) {
                new AdministratorGui();
                frame.dispose();

            }

            @Override
            public void mouseReleased(MouseEvent e) {

            }

            @Override
            public void mouseEntered(MouseEvent e) {

            }

            @Override
            public void mouseExited(MouseEvent e) {

            }
        });


    }

    public void delete(String id){
        DBUtil.jt.update("delete from 班级表 where 班级号=?", new Object[]{id});


//        System.out.println(
//                (jt.update("delete from tb_student where id=?", new Object[]{21})>0
//                        ?"删除成功":"删除失败"));
    }
    public void UpdateClassName(String id,String age){
        DBUtil.jt.update("update 班级表 set 班级名称=? where 班级号=?",
                new Object[]{ id,age});

    }
    public void UpdateClassAcadem(String id,String sex){
        DBUtil.jt.update("update 班级表 set 所属学院=? where 班级号=?",
                new Object[]{ id,sex});

    }
    public void UpdateClassNunber(String id,String clas){
        DBUtil.jt.update("update 班级表 set 班级人数=? where 班级号=?",
                new Object[]{ id,clas});

    }
    public void UpdateClassLeader(String id,String clas){
        DBUtil.jt.update("update 班级表 set 班主任=? where 班级号=?",
                new Object[]{id,clas});

    }

    public static void main(String[] args) {
        new DeleteClassInfoUI();
    }
}

